package com.xiaoke.security.controller;

import com.xiaoke.security.dto.FileInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Date;

/**
 * @Author 小柯
 * @Date 2019/11/2  17:23
 **/

@RestController
@RequestMapping("/file")
@Slf4j
public class FileController {

    private String folder = "/Users/zhailiang/Documents/my/muke/inaction/java/workspace/github/imooc-security-demo/src/main/java/com/imooc/web/controller";

    public FileInfo upload(MultipartFile file) throws IOException {
        log.error("file.getName()" + file.getName());
        log.error("file.getOriginalFilename()" + file.getOriginalFilename());
        log.error("file.getOriginalFilename()" + file.getOriginalFilename());
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        File localFile = new File(folder, new Date().getTime() + ".txt");
        file.transferTo(localFile);

        return new FileInfo(localFile.getAbsolutePath());
    }

}
